home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
0411.ZIP
/
DBCOMRAT.C
< prev
next >
Wrap
Text File
|
1985-10-26
|
2KB
|
90 lines
/*
* Program to read a dBASE program file and count the number of comment and
* program lines in it.
*/
#include "stdio.h"
#define CR 0xd
#define LF 0xa
#define TB 0x9
#define SP 0x20
#define TRUE 1
#define FALSE 0
main(argc,argv)
int argc;
char *argv[];
{
float ratio,
cmcntr,
lfcntr,
code;
int c,
outfile,
infile,
frstchar;
if ((argc == 1) || (argv[1][0] == '?'))
{
puts("\n");
puts("Syntax: DBCOMRAT <infile>\n");
puts("where infile is the filespec for the input data\n");
puts("\n");
puts("The input file should be a dBASE .PRG file. This file is\n");
puts("examined for the number of comment lines within it. The ratio\n");
puts("of comment lines to program lines is output at program end.\n");
puts("\n");
exit(0);
}
if (argv[1][0] == '#')
{
puts("\n");
puts("PROGRAM: DBCOMRAT\n");
puts("Author : Peter Townsend\n");
puts("Date : 25Oct85\n");
puts("Version: 1.1\n");
exit(0);
}
if ((infile = open(argv[1],0)) == -1)
{
printf("\nCannot open input file %s\n",argv[1]);
exit(1);
}
frstchar = TRUE;
lfcntr = 0;
cmcntr = 0;
while ((c = fgetc(infile)) != EOF)
{
if (c == LF)
{
lfcntr++;
frstchar = TRUE;
}
else
{
if (frstchar)
{
if (c == '*')
{
cmcntr++;
frstchar = FALSE;
}
else
{
if ((c != TB) && (c != SP))
{
frstchar = FALSE;
}
}
}
}
}
fclose(infile);
code = lfcntr - cmcntr;
ratio = cmcntr/code;
puts("\n");
printf("There were : %6.0f comment lines\n",cmcntr);
printf(" : %6.0f program lines\n",code);
printf(" : %6.0f total lines\n",lfcntr);
puts("\n");
printf("The ratio of comment to code lines is %.3f : 1\n",ratio);
exit(0);
}